```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Fork/Join框架详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
            color: white;
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .section-divider {
            border-top: 1px solid #e2e8f0;
            margin: 3rem 0;
        }
        .highlight {
            background-color: #e0f2fe;
            padding: 0.2rem 0.4rem;
            border-radius: 0.25rem;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">Java Fork/Join框架</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">高效并行计算的现代解决方案</p>
            <div class="flex justify-center space-x-4">
                <div class="bg-white text-blue-600 px-6 py-3 rounded-full font-semibold shadow-lg hover:bg-blue-50 transition-colors">
                    <i class="fas fa-book-open mr-2"></i>深入解析
                </div>
                <div class="border border-white text-white px-6 py-3 rounded-full font-semibold hover:bg-white hover:bg-opacity-10 transition-colors">
                    <i class="fas fa-laptop-code mr-2"></i>代码示例
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">Fork/Join框架概述</h2>
                <p class="text-lg mb-6 text-gray-700">随着多核处理器的普及，传统的单线程编程方式已经无法充分利用现代计算机的硬件优势。在这种背景下，<span class="highlight">Fork/Join框架</span>作为Java 7引入的一项重要并发工具，为我们提供了一种高效的方式来处理那些可以被递归分割并行执行的任务。</p>
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1731554017837-5b54e96c-a12e-4ad2-8903-7719baeb8e35.png" alt="Fork/Join框架示意图" class="w-full rounded-lg mb-6">
                <p class="text-lg mb-6 text-gray-700">Fork/Join框架利用了"<span class="highlight">分而治之</span>"的思想，将大任务拆解成多个小任务，通过多线程并行执行来加速计算过程，最终合并结果，得到整体任务的结果。</p>
                <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6">
                    <p class="text-blue-800"><i class="fas fa-lightbulb text-blue-500 mr-2"></i><strong>核心优势：</strong>Fork/Join框架的核心优势就在于<span class="font-semibold">任务拆分</span>和<span class="font-semibold">任务合并</span>。当我们遇到一个大规模的计算任务时，Fork/Join框架会通过将这个大任务递归地分解成较小的子任务，然后让每个子任务在不同的线程中执行，最后再将它们的结果合并，得到最终的计算结果。</p>
                </div>
            </div>
        </section>

        <!-- Core Components -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">Fork/Join框架的核心组件</h2>
            <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1731554100859-9dd121d0-1020-4559-afde-0fec4231ee52.png" alt="Fork/Join核心组件" class="w-full rounded-lg mb-8">
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- ForkJoinPool Card -->
                <div class="card bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-project-diagram text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">ForkJoinPool</h3>
                    </div>
                    <p class="text-gray-700 mb-4">ForkJoinPool是Fork/Join框架的核心组件，负责管理和调度任务的执行。它是Java线程池（ExecutorService）的一种特殊实现，优化了并行任务的执行。</p>
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <h4 class="font-semibold text-gray-800 mb-2">工作窃取算法</h4>
                        <p class="text-gray-700 text-sm">ForkJoinPool的工作窃取机制使得线程能够在自己的任务队列为空时，从其他线程的队列中窃取任务。这种机制提高了系统的吞吐量，确保线程池中的所有线程都能够充分工作。</p>
                    </div>
                </div>

                <!-- ForkJoinTask Card -->
                <div class="card bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 p-3 rounded-full mr-4">
                            <i class="fas fa-tasks text-green-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">ForkJoinTask</h3>
                    </div>
                    <p class="text-gray-700 mb-4">ForkJoinTask是Fork/Join框架的基本任务单位，继承自java.util.concurrent.Future，表示一个可以执行和管理的任务。</p>
                    <div class="grid grid-cols-2 gap-4 mt-4">
                        <div class="bg-gray-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-gray-800 text-sm mb-1">RecursiveTask</h4>
                            <p class="text-gray-700 text-xs">表示一个有返回值的任务，通常用于需要返回计算结果的任务。</p>
                        </div>
                        <div class="bg-gray-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-gray-800 text-sm mb-1">RecursiveAction</h4>
                            <p class="text-gray-700 text-xs">表示没有返回值的任务，通常用于执行那些没有明确返回值的任务。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Divide and Conquer -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">分而治之的基本思想</h2>
                <p class="text-lg mb-6 text-gray-700"><span class="highlight">分而治之</span>（Divide and Conquer）是一种算法设计思想，其基本原理是将一个复杂的问题分解成若干个规模较小、相似的子问题，并分别求解这些子问题，最终将各个子问题的解合并得到原问题的解。</p>
                
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="bg-blue-50 p-6 rounded-lg text-center">
                        <div class="bg-blue-100 w-16 h-16 mx-auto rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-cut text-blue-600 text-2xl"></i>
                        </div>
                        <h3 class="font-bold text-gray-800 mb-2">分解</h3>
                        <p class="text-gray-700 text-sm">将原问题分解为若干个规模较小、结构相似的子问题</p>
                    </div>
                    <div class="bg-green-50 p-6 rounded-lg text-center">
                        <div class="bg-green-100 w-16 h-16 mx-auto rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-cog text-green-600 text-2xl"></i>
                        </div>
                        <h3 class="font-bold text-gray-800 mb-2">解决</h3>
                        <p class="text-gray-700 text-sm">如果子问题的规模足够小，则直接求解</p>
                    </div>
                    <div class="bg-purple-50 p-6 rounded-lg text-center">
                        <div class="bg-purple-100 w-16 h-16 mx-auto rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-puzzle-piece text-purple-600 text-2xl"></i>
                        </div>
                        <h3 class="font-bold text-gray-800 mb-2">合并</h3>
                        <p class="text-gray-700 text-sm">将各个子问题的解合并，得到原问题的解</p>
                    </div>
                </div>

                <h3 class="text-xl font-bold mb-4 text-gray-800">经典分治算法示例</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full bg-white rounded-lg overflow-hidden">
                        <thead class="bg-gray-100">
                            <tr>
                                <th class="py-3 px-4 text-left text-gray-700 font-semibold">算法</th>
                                <th class="py-3 px-4 text-left text-gray-700 font-semibold">描述</th>
                                <th class="py-3 px-4 text-left text-gray-700 font-semibold">时间复杂度</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200">
                            <tr>
                                <td class="py-3 px-4">归并排序</td>
                                <td class="py-3 px-4">将数组分为两个子数组，分别排序后合并</td>
                                <td class="py-3 px-4">O(n log n)</td>
                            </tr>
                            <tr class="bg-gray-50">
                                <td class="py-3 px-4">快速排序</td>
                                <td class="py-3 px-4">选择基准元素分割数组，递归排序子数组</td>
                                <td class="py-3 px-4">O(n log n)</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4">二分查找</td>
                                <td class="py-3 px-4">每次将搜索区域折半，逐步缩小范围</td>
                                <td class="py-3 px-4">O(log n)</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- Workflow -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">Fork/Join框架的工作流程</h2>
            <div class="bg-white rounded-xl shadow-md p-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1731554039135-13957d8e-d88a-43c6-a520-c785e81fcf08.png" alt="Fork/Join工作流程" class="w-full rounded-lg mb-8">
                
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="border-l-4 border-blue-500 pl-4">
                        <h3 class="text-xl font-bold mb-3 text-gray-800">1. 任务提交</h3>
                        <p class="text-gray-700">任务通过fork()方法递归拆分并提交到ForkJoinPool。ForkJoinPool负责管理和调度所有任务。</p>
                    </div>
                    <div class="border-l-4 border-green-500 pl-4">
                        <h3 class="text-xl font-bold mb-3 text-gray-800">2. 工作窃取</h3>
                        <p class="text-gray-700">ForkJoinPool使用工作窃取算法平衡负载。每个线程有自己的双端队列，空闲线程会从其他队列窃取任务。</p>
                    </div>
                    <div class="border-l-4 border-purple-500 pl-4">
                        <h3 class="text-xl font-bold mb-3 text-gray-800">3. 任务执行</h3>
                        <p class="text-gray-700">任务通过递归调用fork()和join()实现分解与执行，直到任务足够小直接计算，然后合并结果。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Work Stealing Model -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">Fork/Join框架的工作窃取模型</h2>
            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="flex flex-col md:flex-row items-center mb-8">
                    <div class="md:w-1/2 mb-6 md:mb-0 md:pr-8">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">高效的任务调度策略</h3>
                        <p class="text-gray-700 mb-4">Fork/Join框架采用了<span class="highlight">工作窃取算法</span>（Work Stealing），这是一种优化任务调度和负载均衡的策略。在ForkJoinPool中，每个工作线程都有自己的双端队列（Deque）来存放待执行的任务。</p>
                        <ul class="space-y-2 text-gray-700">
                            <li><i class="fas fa-check-circle text-blue-500 mr-2"></i><strong>LIFO处理：</strong>线程从自己的队列尾部获取任务执行（后进先出）</li>
                            <li><i class="fas fa-check-circle text-blue-500 mr-2"></i><strong>工作窃取：</strong>空闲线程从其他线程队列头部窃取任务</li>
                            <li><i class="fas fa-check-circle text-blue-500 mr-2"></i><strong>负载均衡：</strong>确保所有CPU核心都能充分利用</li>
                        </ul>
                    </div>
                    <div class="md:w-1/2">
                        <div class="bg-gray-100 p-6 rounded-lg">
                            <div class="flex justify-between items-center mb-4">
                                <div class="font-semibold">线程1的任务队列</div>
                                <div class="text-sm text-gray-500">尾部 → 头部</div>
                            </div>
                            <div class="space-y-2">
                                <div class="bg-blue-100 p-3 rounded text-center">任务D</div>
                                <div class="bg-blue-100 p-3 rounded text-center">任务C</div>
                                <div class="bg-blue-100 p-3 rounded text-center">任务B</div>
                                <div class="bg-blue-100 p-3 rounded text-center">任务A</div>
                            </div>
                            <div class="mt-4 text-sm text-gray-600">
                                <i class="fas fa-info-circle mr-1"></i>空闲线程会从其他队列头部窃取任务（如任务A）
                            </div>
                        </div>
                    </div>
                </div>

                <h3 class="text-xl font-bold mb-4 text-gray-800">工作窃取的优势</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-blue-50 p-5 rounded-lg">
                        <h4 class="font-bold mb-2 text-gray-800"><i class="fas fa-balance-scale text-blue-500 mr-2"></i>负载均衡</h4>
                        <p class="text-gray-700 text-sm">工作窃取能够在多核处理器上实现较好的负载均衡。由于线程会窃取其他线程的任务，避免了线程因任务耗尽而空闲的情况。</p>
                    </div>
                    <div class="bg-green-50 p-5 rounded-lg">
                        <h4 class="font-bold mb-2 text-gray-800"><i class="fas fa-tachometer-alt text-green-500 mr-2"></i>减少线程闲置</h4>
                        <p class="text-gray-700 text-sm">通过让空闲线程窃取其他线程的任务，使得线程能够持续工作，减少了线程空闲的时间，提升了并行度。</p>
                    </div>
                    <div class="bg-purple-50 p-5 rounded-lg">
                        <h4 class="font-bold mb-2 text-gray-800"><i class="fas fa-memory text-purple-500 mr-2"></i>提高任务局部性</h4>
                        <p class="text-gray-700 text-sm">线程优先从自己的队列尾部获取任务（LIFO），能够更好地保持任务的局部性，增加缓存命中率。</p>
                    </div>
                    <div class="bg-yellow-50 p-5 rounded-lg">
                        <h4 class="font-bold mb-2 text-gray-800"><i class="fas fa-sliders-h text-yellow-500 mr-2"></i>动态调整负载</h4>
                        <p class="text-gray-700 text-sm">通过工作窃取机制，Fork/Join框架能够动态地调整任务的分配，使得每个线程都能尽量均衡地参与任务执行。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">Fork/Join的优化点</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-8">
                    <p class="text-lg mb-6 text-gray-700">Fork/Join框架通过引入任务拆分和工作窃取机制，极大地提升了并行计算的效率，但在实际应用中，仍然有一些可以进一步优化的地方。</p>
                </div>
                
                <div class="border-t border-gray-200">
                    <div class="grid md:grid-cols-2">
                        <!-- Left Column -->
                        <div class="p-8 border-b md:border-b-0 md:border-r border-gray-200">
                            <div class="flex items-start mb-6">
                                <div class="bg-blue-100 p-3 rounded-full mr-4 flex-shrink-0">
                                    <i class="fas fa-expand-arrows-alt text-blue-600"></i>
                                </div>
                                <div>
                                    <h3 class="text-xl font-bold mb-2 text-gray-800">合理控制任务拆分的粒度</h3>
                                    <p class="text-gray-700">任务拆分的粒度是影响Fork/Join框架性能的一个重要因素。过于细小的任务粒度会导致过多的任务管理开销和高工作窃取频率。</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-green-100 p-3 rounded-full mr-4 flex-shrink-0">
                                    <i class="fas fa-tasks text-green-600"></i>
                                </div>
                                <div>
                                    <h3 class="text-xl font-bold mb-2 text-gray-800">任务队列的管理优化</h3>
                                    <p class="text-gray-700">可以通过调整任务拆分的深度和任务队列的大小来避免频繁的任务窃取。改进线程本地缓存的策略，使得线程尽量处理本地队列中的任务。</p>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Right Column -->
                        <div class="p-8">
                            <div class="flex items-start mb-6">
                                <div class="bg-purple-100 p-3 rounded-full mr-4 flex-shrink-0">
                                    <i class="fas fa-cogs text-purple-600"></i>
                                </div>
                                <div>
                                    <h3 class="text-xl font-bold mb-2 text-gray-800">调优ForkJoinPool的配置</h3>
                                    <p class="text-gray-700">通过合理配置ForkJoinPool的参数，可以进一步提升并行任务的性能。线程数应该与CPU核心数匹配，或根据任务的并行度进行动态调整。</p>
                                    <div class="code-block p-4 mt-3 rounded-lg">
                                        <code class="text-sm text-white">ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());</code>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-yellow-100 p-3 rounded-full mr-4 flex-shrink-0">
                                    <i class="fas fa-random text-yellow-600"></i>
                                </div>
                                <div>
                                    <h3 class="text-xl font-bold mb-2 text-gray-800">减少同步开销</h3>
                                    <p class="text-gray-700">尽量减少线程间的依赖和同步操作，通过改进任务拆分策略减少合并步骤。对于某些场景，可以使用CompletableFuture来替代同步的join()。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Application Scenarios -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">Fork/Join的应用场景</h2>
            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="grid md:grid-cols-2 gap-8">
                    <!-- Left Column -->
                    <div>
                        <div class="flex items-start mb-6">
                            <div class="bg-blue-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-sort-amount-down text-blue-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">分治算法</h3>
                                <p class="text-gray-700">非常适合处理分治算法类型的问题，如并行归并排序、并行快速排序、矩阵运算等。</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start mb-6">
                            <div class="bg-green-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-calculator text-green-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">计算密集型任务</h3>
                                <p class="text-gray-700">特别适合计算密集型的任务，如大数计算、科学计算、图形渲染等。</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-purple-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-database text-purple-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">大规模数据处理</h3>
                                <p class="text-gray-700">适用于MapReduce类型的大规模数据处理，如日志分析、文本数据处理、统计汇总等。</p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Right Column -->
                    <div>
                        <div class="flex items-start mb-6">
                            <div class="bg-yellow-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-project-diagram text-yellow-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">图计算与遍历</h3>
                                <p class="text-gray-700">适用于图计算问题，如并行图遍历、最短路径计算等。</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start mb-6">
                            <div class="bg-red-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-image text-red-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">图像与视频处理</h3>
                                <p class="text-gray-700">图像和视频处理中的很多操作都可以并行化，如图像滤波、图像增强、边缘检测等。</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4 flex-shrink-0">
                                <i class="fas fa-brain text-indigo-600"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-bold mb-2 text-gray-800">机器学习与数据科学</h3>
                                <p class="text-gray-700">适用于数据预处理、特征工程、交叉验证等机器学习和数据科学任务。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Example -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">代码示例</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="bg-gray-800 px-6 py-4 flex items-center">
                    <div class="flex space-x-2 mr-4">
                        <div class="w-3 h-3 rounded-full bg-red-500"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <div class="text-white text-sm">SumTask.java</div>
                </div>
                <div class="p-6 code-block">
                    <pre class="text-sm"><code class="text-gray-300">import java.util.concurrent.RecursiveTask;
import java.util.concurrent.ForkJoinPool;

public class ForkJoinDemo {

    // 定义一个任务类，继承RecursiveTask
    static class SumTask extends RecursiveTask&lt;Long&gt; {
        private int[] array;
        private int start;
        private int end;
        
        // 构造函数
        public SumTask(int[] array, int start, int end) {
            this.array = array;
            this.start = start;
            this.end = end;
        }

        @Override
        protected Long compute() {
            // 如果任务小到一定程度，直接计算
            if (end - start &lt;= 1000) {
                long sum = 0;
                for (int i = start; i &lt; end; i++) {
                    sum += array[i];
                }
                return sum;
            } else {
                // 否则，拆分任务
                int mid = (start + end) / 2;
                SumTask leftTask = new SumTask(array, start, mid);
                SumTask rightTask = new SumTask(array, mid, end);
                
                // 执行拆分任务
                leftTask.fork();
                rightTask.fork();
                
                // 合并结果
                long leftResult = leftTask.join();
                long rightResult = rightTask.join();
                
                return leftResult + rightResult;
            }
        }
    }

    public static void main(String[] args) {
        // 创建一个大的整数数组
        int[] array = new int[100000];
        for (int i = 0; i &lt; array.length; i++) {
            array[i] = 1;  // 假设每个元素为1
        }
        
        // 创建ForkJoinPool
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        
        // 创建任务
        SumTask task = new SumTask(array, 0, array.length);
        
        // 提交任务并等待结果
        long result = forkJoinPool.invoke(task);
        
        System.out.println("Total sum: " + result);
    }
}</code></pre>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-2xl font-bold mb-4">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors" target="_blank">www.yuque.com/jtostring</a>
                <div class="mt-6 flex space-x-4">
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-gray-700 transition-colors">
                        <i class="fab fa-github"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-gray-700 transition-colors">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-gray-700 transition-colors">
                        <i class="fab fa-linkedin-in"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```